package com.tcwlkj.uuService.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.tcwlkj.uuService.MyApp;
import com.tcwlkj.uuService.NetWork.HttpCallBack;
import com.tcwlkj.uuService.NetWork.RetrofitUtils;
import com.tcwlkj.uuService.R;
import com.tcwlkj.uuService.model.CommonResponse;
import com.tcwlkj.uuService.model.MessageDetailModel;
import com.tcwlkj.uuService.utils.PreferencesUtils;
import com.tcwlkj.uuService.utils.ToastUtil;

import java.net.URLDecoder;

import butterknife.Bind;
import butterknife.ButterKnife;
import retrofit2.Call;

/**
 * Created by Administrator on 2017/11/1 0001.
 */

public class MessageDetailActivity extends BaseActivity {
    @Bind(R.id.web_content)
    WebView web_content;
    private String noticeid;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_detail);
        ButterKnife.bind(this);
        noticeid=getIntent().getStringExtra("noticeid");
        changeTitle("消息内容");
        useinfo();
    }

    private void useinfo() {
        Call<CommonResponse<MessageDetailModel>> httpResultCall = RetrofitUtils.getRequest(this, false).useinfo(noticeid);
        httpResultCall.enqueue(new HttpCallBack<CommonResponse<MessageDetailModel>>() {
            @Override
            public void onSuccess(Object t) {
                CommonResponse<MessageDetailModel> commonResponse= (CommonResponse<MessageDetailModel>) t;
                web_content.setWebViewClient(new WebViewClient());
                web_content.loadDataWithBaseURL(null, URLDecoder.decode(commonResponse.getData().getBody()), "text/html", "utf-8", null);
            }
            @Override
            public void onFail(int code, String message) {
                if(code == 40104){
                    useinfo();
                }else {
                    ToastUtil.getInstance().show(message);
                }
            }
        });
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }
}
